<html>
<head><meta charset="utf-8"><title>How does rust-analyzer fetch dependencies? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html">How does rust-analyzer fetch dependencies?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225436615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225436615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jason Axelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225436615">(Feb 07 2021 at 00:09)</a>:</h4>
<p>Hi, I have a question as a fellow LanguageServer implementer, how does rust-analyzer fetch and manage dependencies?</p>



<a name="225436671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225436671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225436671">(Feb 07 2021 at 00:10)</a>:</h4>
<p>through <code>rustup</code> I would assume</p>



<a name="225436680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225436680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225436680">(Feb 07 2021 at 00:10)</a>:</h4>
<p>I would have to pay closer attention next time it updates though</p>



<a name="225436786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225436786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225436786">(Feb 07 2021 at 00:15)</a>:</h4>
<p>From what I recall it uses <code>cargo metadata</code>, this crate is the relevant part for that I believe <a href="https://github.com/rust-analyzer/rust-analyzer/tree/master/crates/project_model/src">https://github.com/rust-analyzer/rust-analyzer/tree/master/crates/project_model/src</a></p>



<a name="225437356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225437356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jason Axelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225437356">(Feb 07 2021 at 00:32)</a>:</h4>
<p>hmmm, thanks for the link, although I'm unable to see where in the code it fetches dependencies. Does rust-analyzer avoid a race condition between when it is fetching dependencies and if the user is fetching dependencies?</p>



<a name="225438091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225438091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225438091">(Feb 07 2021 at 00:54)</a>:</h4>
<p>which dependencies are you interested in?</p>



<a name="225438735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225438735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225438735">(Feb 07 2021 at 01:12)</a>:</h4>
<p>Do you mean the actual download of dependencies / the index? That is handled by Cargo, which has a file lock on the corresponding directories, which should avoid any races.</p>



<a name="225440785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225440785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jason Axelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225440785">(Feb 07 2021 at 02:14)</a>:</h4>
<p>Ah, I see. Cargo handling the race condition makes sense. (I'm not interested in any particular dependency, I'm interested in how dependencies are fetched in general)</p>



<a name="225440791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225440791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jason Axelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225440791">(Feb 07 2021 at 02:15)</a>:</h4>
<p>Thanks! <span aria-label="smiley" class="emoji emoji-1f603" role="img" title="smiley">:smiley:</span></p>



<a name="225441999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225441999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225441999">(Feb 07 2021 at 02:59)</a>:</h4>
<p>It does also use <code>rustup</code> to install the <code>rust-src</code> component</p>



<a name="225467800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225467800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225467800">(Feb 07 2021 at 15:05)</a>:</h4>
<p>Hi <span class="user-mention" data-user-id="387686">@Jason Axelson</span> ! </p>
<p>I believe the best approach here is to let the build system do the heavy lifting. ie, the server asks where the deps are, and the build system provides the server with paths (maybe fetching some from the internet).</p>
<p>One problem here is that the user and the server might invoke the build system concurrently. Solution to that is just to make sure that the build system is concurrency-safe. I submitted some bugs and fixed for Cargo for this, back when I worked on IntelliJ.</p>



<a name="225517836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20does%20rust-analyzer%20fetch%20dependencies%3F/near/225517836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jason Axelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20does.20rust-analyzer.20fetch.20dependencies.3F.html#225517836">(Feb 08 2021 at 09:13)</a>:</h4>
<p>Thanks for the info <span class="user-mention" data-user-id="133169">@matklad</span>, solving it in the build system makes a lot of sense.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>